package com.qj.yantaishan.controller;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.qj.yantaishan.common.core.domain.R;
import com.qj.yantaishan.service.IStorePhysicalVoService;
import com.qj.yantaishan.vo.StorePhysicalVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.qj.yantaishan.common.annotation.Log;
import com.qj.yantaishan.common.enums.BusinessType;
import com.qj.yantaishan.domain.StorePhysical;
import com.qj.yantaishan.service.IStorePhysicalService;
import com.qj.yantaishan.common.core.controller.BaseController;
import com.qj.yantaishan.common.core.domain.AjaxResult;
import com.qj.yantaishan.common.utils.poi.ExcelUtil;
import com.qj.yantaishan.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 *
 * @author qihe
 * @date 2022-07-22
 */
@RestController
@RequestMapping("/yantaishan/StorePhysical")
public class StorePhysicalController extends BaseController {
    private String prefix = "yantaishan/StorePhysical";

    @Autowired
    private IStorePhysicalVoService storePhysicalVoService;

    @GetMapping("list")
    public R getPhysicalList(@RequestParam(required = false, defaultValue = "1") Integer currentPage,
                             @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        Page<StorePhysicalVo> storePhysicalVoPage = new Page<>(currentPage, pageSize);
        final Page<StorePhysicalVo> page = storePhysicalVoService.page(storePhysicalVoPage);
        return R.ok(page);
    }

    @PostMapping
    public R addPhysical(@RequestBody StorePhysicalVo physicalVo) {
        physicalVo.setStoreId(Long.getLong("1"));
        return R.ok(storePhysicalVoService.save(physicalVo));
    }

    @PutMapping()
    public R update(@RequestBody StorePhysicalVo physicalVo) {
        return R.ok(storePhysicalVoService.updateById(physicalVo));
    }

    @DeleteMapping()
    public R delete(@RequestParam(required = true) Integer physicalId) {
        return R.ok(storePhysicalVoService.removeById(physicalId));
    }

    @GetMapping
    public R get(@RequestParam(required = true) Integer physicalId) {
        return R.ok(storePhysicalVoService.getById(physicalId));
    }

    @PutMapping("update/main")
    public R modify(@RequestParam(required = true) Integer physicalId) {
        //现将其他店设为不是主店
        storePhysicalVoService.update(new LambdaUpdateWrapper<StorePhysicalVo>().set(StorePhysicalVo::getMainStore, 0));
        //设为主店
        storePhysicalVoService.update(new LambdaUpdateWrapper<StorePhysicalVo>().set(StorePhysicalVo::getMainStore, 1).eq(StorePhysicalVo::getPigcmsId, physicalId));
        return R.ok();
    }


}
